// 使用select实现Channel超时机制
package main

import (
    "time"
    "fmt"
)

func main() {
    ch := make(chan bool, 1)
    timeout := make(chan bool, 1)
    go func() {
        time.Sleep(2 * time.Second)
        timeout <- true
    }()
    select {
    case <-ch:
    case <-timeout:
        fmt.Println("timeout...")
        break
    }
}
